package ru.tulupov.collectionsbenchmark.tester;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

public abstract class SetTester<T extends Comparable<T>> extends Tester<T> {
	private static final Logger LOGGER = Logger.getLogger(SetTester.class);

	private Set<T> set;

	public SetTester(Set<T> set) {
		super(set);
		this.set = set;
	}
@Override
	public void randomAccess(int count) {
		SecureRandom random = new SecureRandom();

		List<T> keys = new ArrayList<T>(set);

		int hash = 0;
		for (int i = 0; i < count; i++) {
			T obj = keys.get(random.nextInt(keys.size()));
			if (set.contains(obj)) {
				hash += obj.hashCode();
			}
		}
		LOGGER.info(String.format("Random access set [%d].", hash));
	}
}
